﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using PMS.Infrastructure;
using PMS.Web.Infrastructure;
using PMS.Web.Infrastructure.WebHostExtensions;
using Microsoft.Extensions.DependencyInjection;

namespace PMS.Web
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args)
                .MigrateDbContext<PMSContext>((context,service) => {
                    var env = service.GetService<IHostingEnvironment>();            
                    var logger = service.GetService<ILogger<PMSContextSeed>>();
                    new PMSContextSeed().SeedAsync(context, env, logger).Wait();                  
                })                
                .Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();
    }
}
